package com.tiny.mirror.service.product.application.command;

import com.api.tiny.mirror.service.product.request.CreateAppRequest;
import com.api.tiny.mirror.service.product.request.UpdateAppRequest;
import com.tiny.mirror.service.product.application.convert.AppConvert;
import com.tiny.mirror.service.product.domain.app.App;
import com.tiny.mirror.service.product.domain.app.service.AppDomainService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: liujsh
 * @Description:
 * @Date: Create in 2023/9/27
 */
@Service
public class AppCmdService {

  @Resource
  private AppDomainService appDomainService;

  @Transactional
  public Long create(CreateAppRequest request) {
    App app = AppConvert.convertToApp(request);
    return appDomainService.create(app);
  }

  @Transactional
  public void update(UpdateAppRequest request) {
    App app = AppConvert.convertToApp(request);
    appDomainService.update(request.getId(), app);
  }

  @Transactional
  public Integer delete(List<Long> ids) {
    int result = 0;
    for (Long id : ids) {
      appDomainService.delete(id);
      result++;
    }
    return result;
  }
}
